﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace PlusPlusPaint.Layers
{
    abstract class BasicLayer : ILayer
    {
        #region member variables
        private Action toBeCalledOnDelete;
        protected int cxLoc, cyLoc, lxSize, lySize;
        protected bool empty;
        #endregion

        #region properties
        public abstract Point Location
        {
            get;
        }

        public abstract Size Size
        {
            get;
        }

        public abstract Rectangle ClientRectangle
        {
            get;
        }

        public bool Visible
        {
            get;
            set;
        }

        public abstract bool CanFreeDraw
        {
            get;
        }

        public abstract bool Explodable
        {
            get;
        }

        public string Name
        {
            get;
            set;
        }
        #endregion

        #region events
        public EventHandler Invalidated;
        #endregion

        #region abstract methods
        public abstract bool PositionIsInHitbox(Point p);
        public abstract void ApplyToolToPoint(Tools.ISketchTool t, Point p);
        public abstract bool CanHaveToolApplied(Tools.ISketchTool t);
        public abstract ILayer Clone();
        public abstract void BurnOn(Image i);
        public abstract SerializedObject Serialize();
        public abstract void Deserialize(SerializedObject node);
        #endregion

        #region virtual methods
        /// <summary>
        /// Return a list of all the layers contained in the layer, or the
        /// layer itself if it is not meant to contain sublayers.
        /// </summary>
        public virtual IList<ILayer> ExplodeLayer()
        {
            IList<ILayer> l = new List<ILayer>();
            l.Add(this);
            return l;
        }
        #endregion

        #region public methods
        public void Delete()
        {
            if (this.toBeCalledOnDelete != null)
                this.toBeCalledOnDelete();
            this.toBeCalledOnDelete = null;
        }

        public void CallOnDeletion(Action f)
        {
            this.toBeCalledOnDelete += f;
        }

        public void Invalidate()
        {
            if (this.Invalidated != null)
                this.Invalidated(this, EventArgs.Empty);
        }

        public void CallOnInvalidate(EventHandler eh)
        {
            Invalidated += eh;
        }
        #endregion
    }
}
